package com.fujiyang.service.Impl;

import com.fujiyang.mapper.UserMapper;
import com.fujiyang.service.UserService;
import com.fujiyang.dto.LoginDTO;
import com.fujiyang.entity.User;
import com.fujiyang.result.Result;
import com.fujiyang.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVO login(LoginDTO loginDTO) {
        // 查询数据库获取用户信息
        User user = userMapper.findByUsernameAndPassword(loginDTO.getUsername(), loginDTO.getPassword());

        if (user != null) {
            // 将User实体转换为UserVO视图对象
            UserVO userVO = new UserVO();
            BeanUtils.copyProperties(user, userVO);
            userVO.setToken("your_generated_token_here"); // 根据实际情况生成token
            return userVO;
        } else {
            throw new RuntimeException("用户名或密码错误");
        }
    }
}